-[ sponsor this site! ]-

CGI Library
Enough people have asked me about CGI's, how to do them, etc., that I
thought I'd start a little page with links to some of the
more common/usual stuff. I hope you find it helpful.
This page is now part of the Web Engineer's Toolbox.. Visit the toolbox for more useful web goodies and information.
All my CGI's are written in Perl on Unix.
For more info about Perl, please visit our
Perl Archive here
on Metronet, which is maintained by Bill Middleton
(wjm@metronet.com).
Also, while it isn't available as a generic CGI, I've written a
256 color square you can use to find the RGB
value of a given color. It's useful for picking out background, text,
and link colors for documents.
NOTE:
Here are a few tips to help get your cgi's working on your server. First,
be sure that your server supports cgi execution. If not, you'll have to
put the cgi in the system's cgi-bin.
Second, be sure you chmod 755 scriptname.cgi so that it is
executable. And finally, if you download these scripts to a PC,
then re-upload them to another unix server, be sure to upload them as
ASCII rather than binary.
Mailto CGI's:
The first CGI that most folks want to do is one that emails them the
output from some form. There is a good general purpose one on the
above archive, and in fact it is the same form-mail.pl that I have
taken and modified a hundred times or more for this sort of thing.
- form-mail.pl - the original script,
if you feel like customizing your own
- mail-form.pl - a simplified, generic
version of the above script, this one only requires one change
(to the $recipient of the email) to be universally usable).
Imagemaps are a fairly common phenomenon on the Web. An
imagemaps is just a gif image that is "clickable" - that is, you click
on a certain part of the image, and it sends you off to a new page.
I've written an imagemap tutorial that describes how to set one up. Admittedly
this tutorial is written for people using Metronet to host their pages,
but it does still give a pretty good general idea for anyone wanting
to set up an imagemap.
Counters are popular, although there's some dissention among
HTML designers as to whether a graphical counter on a page is a good idea.
If you have low hit counts, it can be a negative thing, only emphasizing just
how few hits you're getting. High counts make counters nice, but still
a debatable design element. But enough philosophizing, here's some code:
- counter.pl is a simple sort of "hidden" counter.
It is designed to be used in lieu of an image tag, so instead of doing
img src="whatever.gif", you might use img src="counter.cgi". The script
increments a counter in a file, then returns the gif image. The person
visiting your page need never know you have an embedded counter going.
(There's one on this page, too!)
- ad-counter.pl - a variation on the counter.pl
program, this script is designed to work in conjunction with a
server-side include call. It will increment a counter, then return
the URL and gif image for a given ad. This script can be expanded upon
to allow for multiple rotating ads. Here's a
sample file that shows it in action.
Inline Animation, or the Netscape push-pull
hack, is not that difficult. The hardest part is usually finding a script
to do the actual animation. Here's a simple perl script that does it. I
hacked this from a version of nph-animate, or something like that... I don't
remember now.
You have to edit it to replace the various gif filenames that will
be the different "frames" of your animation, but that's it.
Server-push animation is almost uncool now; it's more popular and common
(and considerably easier) to simply create an
animated gif for
this, though many people find animated gifs annoying as they constantly
reload images from the disk cache.
Redirection Scripts may be necessary if you have a page that supports
certain Netscape-specific features, and want to only show that page to
visitors who are actually using Netscape. This example is the one I use
for my homepage; in lieu of any index.html file, the server hits this script
(named index.cgi) and redirects the incoming request to the proper html file.
Finger Script - this can be modified to perform basically any
unix command, and print the output to a web page.
That's about all I have for now, though I welcome suggestions for
additions to my cookbook of generic CGI's. Certainly there's lots of
need for specialized CGI's depending on your application, and if you're
wanting to learn how to write CGI's, I'll suggest these books:
- Learning Perl,
by
Randal L. Schwartz - this leads you through writing perl programs,
from basic to more complex. Good if you're just learning programming.
- Programming Perl,
by Randal Schwartz and Larry Wall - the definitive reference, this has
descriptions of all the perl functions, and some real-world examples.
If you're familiar with other programming languages, this might be best
for you.
- The Perl5 Desktop Reference
by Johan Vromans - this is not a complete book, but rather a handy
guide to all the various functions, operators, variables, etc. in
Perl, including the new Perl 5 functions. This is useful as a companion
to one of the above books.
- CGI Programming
On the World Wide Web - By Shishir Gundavaram, this book
explores writing CGI's in perl for Web applications. Plenty of
excellent information.
There are also (at least) two newsgroups I would recommend:
Interested in learning perl online? Visit the
Online Perl Class part
of this site.
Kira's Home |
Toolbox